define(["jquery"],function($){
	var quest = {};

	/**
	 * tpl模板
	 */
	quest.tpl = function(){
		return 	'<script id="tpl_question_getLabelsHidden" type="text/html">'+
				'	<input type="hidden" class="qaCard-getLabelsHidden" data-getLabelRelationId="{{getLabelRelationId}}" name="{{name}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}">'+
				'</script>';
	}

	/**
	 * 赋值
	 */
	quest.setValue = function($dom,value){
		if( value ) $dom.val(value.quesValue);
	}

	/**
	 * 获取value（保存时，获取每个dom对应的答案）
	 */
	quest.getValue = function($dom,name){
		var value = {};
		var getLabelRelationId = $dom.attr("data-getLabelRelationId");
		var $dom2 = $dom.parents("form").find(".qaCard[data-getLabelRelationId="+ getLabelRelationId +"]");
		var arr = [];
		// 暂时只支持question_radioRelation
		$dom2.each(function(){
			var val = $(this).find("input[type='radio']:checked").attr("data-abnormal");
			var label = $(this).find(".control-label").text(); // 异常
			var index = $.inArray(label,arr);
			if(val && val == "1" && index == -1){
				arr.push(label);
			}
		});
		var str = arr.join("、");
		value.quesValue = str;
		value.quesId = $dom.attr("data-quesId");
		value.deCode = $dom.attr("data-deCode");
		value.innDeCode = $dom.attr("data-innDeCode");
		return value;
	}

	return quest;
});